package option;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class Insert implements MY{
    @Override
    public void work(BookList booklist) {
        System.out.println("新增图书");
        System.out.println("请输入你要新增的图书名");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        System.out.println("作者");
        String author=scanner.nextLine();
        System.out.println("类型");
        String type=scanner.nextLine();
        System.out.println("价格");
        int price=scanner.nextInt();
        Book book=new Book(name,author,type,price);
        //有这本书
        int size=booklist.getUsedSize();
        for (int i=0;i<size;i++){
            Book book1=booklist.getBooks(i);
            if (book.getName().equals(name)){
                System.out.println("这本书已经在书架上");
                return;
            }
        }
        if(size==booklist.getUsedSize())
        {
            System.out.println("这个书架满了");
        }else {
            booklist.setBooks(size,book);
            booklist.setUsedSize(size+1);
        }
    }
}
